/*
 * @Description:
 * @FilePath: download.js
 */
const log = require('electron-log');

const fileTransferHelper = require('./fileTransferHelper');

log.info('下载线程文件已加载....');

process.parentPort.on('message', (e) => {
    const port = e.ports[0];

    fileTransferHelper.createServiceInstance({ downloadPort: port });

    log.info('下载线程启动...');

    // fileTransferHelper.resumeAllDownloadTask();

    port.on('message', (e) => {
        log.info('下载任务启动....');
        fileTransferHelper.createDownloadTask(e.data);
    });

    port.start();
});

// 必要的全局错误捕获
process.on('uncaughtException', error => {
    log.error(error.stack || JSON.stringify(error));
    // app.exit();
});